{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.124086</td>\n",
       "      <td>0.123077</td>\n",
       "      <td>0.124692</td>\n",
       "      <td>0.123098</td>\n",
       "      <td>0.121993</td>\n",
       "      <td>0.120885</td>\n",
       "      <td>0.120650</td>\n",
       "      <td>0.122520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.125157</td>\n",
       "      <td>0.121047</td>\n",
       "      <td>0.119458</td>\n",
       "      <td>0.121360</td>\n",
       "      <td>0.123017</td>\n",
       "      <td>0.120512</td>\n",
       "      <td>0.123048</td>\n",
       "      <td>0.122855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.125133</td>\n",
       "      <td>0.125864</td>\n",
       "      <td>0.122109</td>\n",
       "      <td>0.126549</td>\n",
       "      <td>0.124533</td>\n",
       "      <td>0.121847</td>\n",
       "      <td>0.120396</td>\n",
       "      <td>0.123333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.125903</td>\n",
       "      <td>0.122256</td>\n",
       "      <td>0.125582</td>\n",
       "      <td>0.123162</td>\n",
       "      <td>0.122565</td>\n",
       "      <td>0.122018</td>\n",
       "      <td>0.124485</td>\n",
       "      <td>0.125027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.123719</td>\n",
       "      <td>0.128365</td>\n",
       "      <td>0.121615</td>\n",
       "      <td>0.123504</td>\n",
       "      <td>0.119830</td>\n",
       "      <td>0.126062</td>\n",
       "      <td>0.123403</td>\n",
       "      <td>0.122291</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6  \\\n",
       "0  0.124086  0.123077  0.124692  0.123098  0.121993  0.120885  0.120650   \n",
       "1  0.125157  0.121047  0.119458  0.121360  0.123017  0.120512  0.123048   \n",
       "2  0.125133  0.125864  0.122109  0.126549  0.124533  0.121847  0.120396   \n",
       "3  0.125903  0.122256  0.125582  0.123162  0.122565  0.122018  0.124485   \n",
       "4  0.123719  0.128365  0.121615  0.123504  0.119830  0.126062  0.123403   \n",
       "\n",
       "          7  \n",
       "0  0.122520  \n",
       "1  0.122855  \n",
       "2  0.123333  \n",
       "3  0.125027  \n",
       "4  0.122291  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('data/data_rms_bearing_1.csv', header=None)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.12408584],\n",
       "       [0.1251568 ],\n",
       "       [0.1251332 ],\n",
       "       ...,\n",
       "       [0.29009982],\n",
       "       [0.27928441],\n",
       "       [0.32616112]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.array(data[0]).reshape(-1, 1) # untuk merubah bentuk matriks\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from hmmlearn.hmm import GMMHMM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "         1        4666.1368             +nan\n",
      "         2        6460.7413       +1794.6046\n",
      "         3        6990.1551        +529.4138\n",
      "         4        7261.4450        +271.2899\n",
      "         5        7742.2772        +480.8322\n",
      "         6        8522.2066        +779.9294\n",
      "         7        9151.8987        +629.6921\n",
      "         8        9319.8577        +167.9590\n",
      "         9        9332.2959         +12.4382\n",
      "        10        9334.7286          +2.4327\n",
      "        11        9337.0036          +2.2750\n",
      "        12        9340.3349          +3.3314\n",
      "        13        9346.4186          +6.0837\n",
      "        14        9358.5970         +12.1785\n",
      "        15        9397.8525         +39.2555\n",
      "        16        9544.9234        +147.0708\n",
      "        17        9670.5235        +125.6001\n",
      "        18        9685.1721         +14.6486\n",
      "        19        9688.4819          +3.3097\n",
      "        20        9689.3747          +0.8929\n",
      "        21        9689.8394          +0.4647\n",
      "        22        9690.1109          +0.2715\n",
      "        23        9690.2765          +0.1657\n",
      "        24        9690.3821          +0.1056\n",
      "        25        9690.4534          +0.0713\n",
      "        26        9690.5051          +0.0517\n",
      "        27        9690.5459          +0.0408\n",
      "        28        9690.5810          +0.0350\n",
      "        29        9690.6133          +0.0324\n",
      "        30        9690.6452          +0.0318\n",
      "        31        9690.6780          +0.0328\n",
      "        32        9690.7132          +0.0352\n",
      "        33        9690.7521          +0.0389\n",
      "        34        9690.7962          +0.0442\n",
      "        35        9690.8478          +0.0515\n",
      "        36        9690.9092          +0.0614\n",
      "        37        9690.9836          +0.0744\n",
      "        38        9691.0742          +0.0906\n",
      "        39        9691.1827          +0.1085\n",
      "        40        9691.3062          +0.1235\n",
      "        41        9691.4343          +0.1281\n",
      "        42        9691.5525          +0.1181\n",
      "        43        9691.6516          +0.0992\n",
      "        44        9691.7327          +0.0810\n",
      "        45        9691.8013          +0.0686\n",
      "        46        9691.8625          +0.0613\n",
      "        47        9691.9195          +0.0570\n",
      "        48        9691.9737          +0.0541\n",
      "        49        9692.0257          +0.0520\n",
      "        50        9692.0758          +0.0501\n",
      "        51        9692.1242          +0.0484\n",
      "        52        9692.1710          +0.0468\n",
      "        53        9692.2162          +0.0452\n",
      "        54        9692.2600          +0.0437\n",
      "        55        9692.3023          +0.0423\n",
      "        56        9692.3431          +0.0409\n",
      "        57        9692.3827          +0.0395\n",
      "        58        9692.4209          +0.0382\n",
      "        59        9692.4578          +0.0370\n",
      "        60        9692.4936          +0.0357\n",
      "        61        9692.5281          +0.0345\n",
      "        62        9692.5615          +0.0334\n",
      "        63        9692.5938          +0.0323\n",
      "        64        9692.6250          +0.0312\n",
      "        65        9692.6551          +0.0302\n",
      "        66        9692.6843          +0.0292\n",
      "        67        9692.7125          +0.0282\n",
      "        68        9692.7397          +0.0272\n",
      "        69        9692.7661          +0.0263\n",
      "        70        9692.7915          +0.0255\n",
      "        71        9692.8161          +0.0246\n",
      "        72        9692.8399          +0.0238\n",
      "        73        9692.8629          +0.0230\n",
      "        74        9692.8851          +0.0222\n",
      "        75        9692.9066          +0.0215\n",
      "        76        9692.9274          +0.0208\n",
      "        77        9692.9474          +0.0201\n",
      "        78        9692.9668          +0.0194\n",
      "        79        9692.9855          +0.0187\n",
      "        80        9693.0036          +0.0181\n",
      "        81        9693.0211          +0.0175\n",
      "        82        9693.0380          +0.0169\n",
      "        83        9693.0544          +0.0164\n",
      "        84        9693.0704          +0.0160\n",
      "        85        9693.0868          +0.0163\n",
      "        86        9693.1069          +0.0201\n",
      "        87        9693.1484          +0.0415\n",
      "        88        9693.3043          +0.1559\n",
      "        89        9693.9644          +0.6601\n",
      "        90        9695.4632          +1.4987\n",
      "        91        9696.4070          +0.9439\n",
      "        92        9696.6291          +0.2220\n",
      "        93        9696.7209          +0.0918\n",
      "        94        9696.8081          +0.0872\n",
      "        95        9696.9073          +0.0992\n",
      "        96        9697.0168          +0.1095\n",
      "        97        9697.1353          +0.1185\n",
      "        98        9697.2926          +0.1573\n",
      "        99        9697.5868          +0.2942\n",
      "       100        9698.1825          +0.5958\n",
      "       101        9698.8584          +0.6758\n",
      "       102        9699.1193          +0.2609\n",
      "       103        9699.1713          +0.0520\n",
      "       104        9699.1881          +0.0168\n",
      "       105        9699.1993          +0.0112\n",
      "       106        9699.2087          +0.0095\n"
     ]
    }
   ],
   "source": [
    "model = GMMHMM(n_components=3, n_mix=2, \n",
    "               n_iter=1000, random_state=100,\n",
    "               verbose=True).fit(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 0., 0.])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.startprob_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[9.94793773e-001, 5.20622693e-003, 0.00000000e+000],\n",
       "       [8.20766543e-217, 9.99322213e-001, 6.77786924e-004],\n",
       "       [2.05132058e-003, 5.22983204e-049, 9.97948679e-001]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.transmat_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.20591491, 0.79408509],\n",
       "       [0.69713767, 0.30286233],\n",
       "       [0.9859749 , 0.0140251 ]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.weights_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "logprob, best_path = model.decode(X, algorithm='viterbi')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9697.87802398643"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logprob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, ..., 0, 0, 0])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_path"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Model Terbaik"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "         1        4666.1368             +nan\n",
      "         2        6460.7413       +1794.6046\n",
      "         3        6990.1551        +529.4138\n",
      "         4        7261.4450        +271.2899\n",
      "         5        7742.2772        +480.8322\n",
      "         6        8522.2066        +779.9294\n",
      "         7        9151.8987        +629.6921\n",
      "         8        9319.8577        +167.9590\n",
      "         9        9332.2959         +12.4382\n",
      "        10        9334.7286          +2.4327\n",
      "        11        9337.0036          +2.2750\n",
      "        12        9340.3349          +3.3314\n",
      "        13        9346.4186          +6.0837\n",
      "        14        9358.5970         +12.1785\n",
      "        15        9397.8525         +39.2555\n",
      "        16        9544.9234        +147.0708\n",
      "        17        9670.5235        +125.6001\n",
      "        18        9685.1721         +14.6486\n",
      "        19        9688.4819          +3.3097\n",
      "        20        9689.3747          +0.8929\n",
      "        21        9689.8394          +0.4647\n",
      "        22        9690.1109          +0.2715\n",
      "        23        9690.2765          +0.1657\n",
      "        24        9690.3821          +0.1056\n",
      "        25        9690.4534          +0.0713\n",
      "        26        9690.5051          +0.0517\n",
      "        27        9690.5459          +0.0408\n",
      "        28        9690.5810          +0.0350\n",
      "        29        9690.6133          +0.0324\n",
      "        30        9690.6452          +0.0318\n",
      "        31        9690.6780          +0.0328\n",
      "        32        9690.7132          +0.0352\n",
      "        33        9690.7521          +0.0389\n",
      "        34        9690.7962          +0.0442\n",
      "        35        9690.8478          +0.0515\n",
      "        36        9690.9092          +0.0614\n",
      "        37        9690.9836          +0.0744\n",
      "        38        9691.0742          +0.0906\n",
      "        39        9691.1827          +0.1085\n",
      "        40        9691.3062          +0.1235\n",
      "        41        9691.4343          +0.1281\n",
      "        42        9691.5525          +0.1181\n",
      "        43        9691.6516          +0.0992\n",
      "        44        9691.7327          +0.0810\n",
      "        45        9691.8013          +0.0686\n",
      "        46        9691.8625          +0.0613\n",
      "        47        9691.9195          +0.0570\n",
      "        48        9691.9737          +0.0541\n",
      "        49        9692.0257          +0.0520\n",
      "        50        9692.0758          +0.0501\n",
      "        51        9692.1242          +0.0484\n",
      "        52        9692.1710          +0.0468\n",
      "        53        9692.2162          +0.0452\n",
      "        54        9692.2600          +0.0437\n",
      "        55        9692.3023          +0.0423\n",
      "        56        9692.3431          +0.0409\n",
      "        57        9692.3827          +0.0395\n",
      "        58        9692.4209          +0.0382\n",
      "        59        9692.4578          +0.0370\n",
      "        60        9692.4936          +0.0357\n",
      "        61        9692.5281          +0.0345\n",
      "        62        9692.5615          +0.0334\n",
      "        63        9692.5938          +0.0323\n",
      "        64        9692.6250          +0.0312\n",
      "        65        9692.6551          +0.0302\n",
      "        66        9692.6843          +0.0292\n",
      "        67        9692.7125          +0.0282\n",
      "        68        9692.7397          +0.0272\n",
      "        69        9692.7661          +0.0263\n",
      "        70        9692.7915          +0.0255\n",
      "        71        9692.8161          +0.0246\n",
      "        72        9692.8399          +0.0238\n",
      "        73        9692.8629          +0.0230\n",
      "        74        9692.8851          +0.0222\n",
      "        75        9692.9066          +0.0215\n",
      "        76        9692.9274          +0.0208\n",
      "        77        9692.9474          +0.0201\n",
      "        78        9692.9668          +0.0194\n",
      "        79        9692.9855          +0.0187\n",
      "        80        9693.0036          +0.0181\n",
      "        81        9693.0211          +0.0175\n",
      "        82        9693.0380          +0.0169\n",
      "        83        9693.0544          +0.0164\n",
      "        84        9693.0704          +0.0160\n",
      "        85        9693.0868          +0.0163\n",
      "        86        9693.1069          +0.0201\n",
      "        87        9693.1484          +0.0415\n",
      "        88        9693.3043          +0.1559\n",
      "        89        9693.9644          +0.6601\n",
      "        90        9695.4632          +1.4987\n",
      "        91        9696.4070          +0.9439\n",
      "        92        9696.6291          +0.2220\n",
      "        93        9696.7209          +0.0918\n",
      "        94        9696.8081          +0.0872\n",
      "        95        9696.9073          +0.0992\n",
      "        96        9697.0168          +0.1095\n",
      "        97        9697.1353          +0.1185\n",
      "        98        9697.2926          +0.1573\n",
      "        99        9697.5868          +0.2942\n",
      "       100        9698.1825          +0.5958\n",
      "       101        9698.8584          +0.6758\n",
      "       102        9699.1193          +0.2609\n",
      "       103        9699.1713          +0.0520\n",
      "       104        9699.1881          +0.0168\n",
      "       105        9699.1993          +0.0112\n",
      "       106        9699.2087          +0.0095\n",
      "         1        4252.7344             +nan\n",
      "         2        6258.9399       +2006.2055\n",
      "         3        6979.8698        +720.9299\n",
      "         4        7288.6007        +308.7309\n",
      "         5        7738.6116        +450.0109\n",
      "         6        8415.1799        +676.5683\n",
      "         7        9150.1968        +735.0169\n",
      "         8        9261.7273        +111.5305\n",
      "         9        9262.9480          +1.2207\n",
      "        10        9263.3545          +0.4065\n",
      "        11        9263.6938          +0.3393\n",
      "        12        9264.0225          +0.3287\n",
      "        13        9264.3821          +0.3596\n",
      "        14        9264.8169          +0.4348\n",
      "        15        9265.3769          +0.5600\n",
      "        16        9266.1144          +0.7375\n",
      "        17        9267.0765          +0.9621\n",
      "        18        9268.2953          +1.2188\n",
      "        19        9269.7774          +1.4821\n",
      "        20        9271.4954          +1.7180\n",
      "        21        9273.3818          +1.8864\n",
      "        22        9275.3296          +1.9479\n",
      "        23        9277.2075          +1.8778\n",
      "        24        9278.8918          +1.6843\n",
      "        25        9280.3040          +1.4122\n",
      "        26        9281.4281          +1.1241\n",
      "        27        9282.2973          +0.8692\n",
      "        28        9282.9665          +0.6692\n",
      "        29        9283.4902          +0.5236\n",
      "        30        9283.9118          +0.4216\n",
      "        31        9284.2625          +0.3507\n",
      "        32        9284.5634          +0.3009\n",
      "        33        9284.8283          +0.2649\n",
      "        34        9285.0663          +0.2379\n",
      "        35        9285.2830          +0.2168\n",
      "        36        9285.4826          +0.1996\n",
      "        37        9285.6677          +0.1851\n",
      "        38        9285.8403          +0.1726\n",
      "        39        9286.0020          +0.1617\n",
      "        40        9286.1540          +0.1520\n",
      "        41        9286.2974          +0.1434\n",
      "        42        9286.4330          +0.1356\n",
      "        43        9286.5615          +0.1286\n",
      "        44        9286.6838          +0.1222\n",
      "        45        9286.8003          +0.1165\n",
      "        46        9286.9116          +0.1113\n",
      "        47        9287.0181          +0.1065\n",
      "        48        9287.1203          +0.1022\n",
      "        49        9287.2185          +0.0982\n",
      "        50        9287.3130          +0.0945\n",
      "        51        9287.4041          +0.0911\n",
      "        52        9287.4920          +0.0879\n",
      "        53        9287.5769          +0.0849\n",
      "        54        9287.6589          +0.0820\n",
      "        55        9287.7382          +0.0793\n",
      "        56        9287.8149          +0.0766\n",
      "        57        9287.8889          +0.0741\n",
      "        58        9287.9605          +0.0716\n",
      "        59        9288.0296          +0.0691\n",
      "        60        9288.0962          +0.0666\n",
      "        61        9288.1604          +0.0642\n",
      "        62        9288.2221          +0.0617\n",
      "        63        9288.2813          +0.0593\n",
      "        64        9288.3381          +0.0568\n",
      "        65        9288.3924          +0.0543\n",
      "        66        9288.4443          +0.0518\n",
      "        67        9288.4936          +0.0493\n",
      "        68        9288.5404          +0.0468\n",
      "        69        9288.5848          +0.0444\n",
      "        70        9288.6267          +0.0419\n",
      "        71        9288.6661          +0.0394\n",
      "        72        9288.7031          +0.0370\n",
      "        73        9288.7378          +0.0347\n",
      "        74        9288.7701          +0.0323\n",
      "        75        9288.8002          +0.0301\n",
      "        76        9288.8281          +0.0279\n",
      "        77        9288.8539          +0.0258\n",
      "        78        9288.8776          +0.0238\n",
      "        79        9288.8994          +0.0218\n",
      "        80        9288.9194          +0.0200\n",
      "        81        9288.9377          +0.0183\n",
      "        82        9288.9543          +0.0166\n",
      "        83        9288.9694          +0.0151\n",
      "        84        9288.9830          +0.0137\n",
      "        85        9288.9954          +0.0123\n",
      "        86        9289.0065          +0.0111\n",
      "        87        9289.0165          +0.0100\n",
      "         1        4232.8984             +nan\n",
      "         2        6236.0722       +2003.1738\n",
      "         3        6942.3914        +706.3193\n",
      "         4        7235.4102        +293.0188\n",
      "         5        7621.1665        +385.7563\n",
      "         6        8193.2641        +572.0975\n",
      "         7        8901.7005        +708.4365\n",
      "         8        9065.3153        +163.6148\n",
      "         9        9082.4605         +17.1452\n",
      "        10        9086.0436          +3.5831\n",
      "        11        9089.7020          +3.6584\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        12        9094.0867          +4.3847\n",
      "        13        9100.0209          +5.9342\n",
      "        14        9112.0632         +12.0423\n",
      "        15        9150.6207         +38.5575\n",
      "        16        9274.7259        +124.1053\n",
      "        17        9402.1423        +127.4164\n",
      "        18        9413.0511         +10.9088\n",
      "        19        9414.4564          +1.4053\n",
      "        20        9415.2488          +0.7924\n",
      "        21        9415.9214          +0.6726\n",
      "        22        9416.5492          +0.6278\n",
      "        23        9417.1520          +0.6028\n",
      "        24        9417.7367          +0.5847\n",
      "        25        9418.3065          +0.5697\n",
      "        26        9418.8625          +0.5561\n",
      "        27        9419.4052          +0.5427\n",
      "        28        9419.9343          +0.5290\n",
      "        29        9420.4489          +0.5146\n",
      "        30        9420.9480          +0.4991\n",
      "        31        9421.4306          +0.4826\n",
      "        32        9421.8957          +0.4651\n",
      "        33        9422.3426          +0.4469\n",
      "        34        9422.7708          +0.4282\n",
      "        35        9423.1802          +0.4095\n",
      "        36        9423.5712          +0.3910\n",
      "        37        9423.9444          +0.3732\n",
      "        38        9424.3007          +0.3563\n",
      "        39        9424.6412          +0.3405\n",
      "        40        9424.9673          +0.3261\n",
      "        41        9425.2803          +0.3130\n",
      "        42        9425.5816          +0.3013\n",
      "        43        9425.8725          +0.2909\n",
      "        44        9426.1543          +0.2818\n",
      "        45        9426.4281          +0.2738\n",
      "        46        9426.6949          +0.2668\n",
      "        47        9426.9557          +0.2608\n",
      "        48        9427.2112          +0.2555\n",
      "        49        9427.4620          +0.2508\n",
      "        50        9427.7087          +0.2467\n",
      "        51        9427.9518          +0.2431\n",
      "        52        9428.1916          +0.2398\n",
      "        53        9428.4285          +0.2369\n",
      "        54        9428.6627          +0.2342\n",
      "        55        9428.8945          +0.2318\n",
      "        56        9429.1241          +0.2296\n",
      "        57        9429.3516          +0.2275\n",
      "        58        9429.5772          +0.2256\n",
      "        59        9429.8010          +0.2238\n",
      "        60        9430.0232          +0.2222\n",
      "        61        9430.2439          +0.2207\n",
      "        62        9430.4632          +0.2193\n",
      "        63        9430.6811          +0.2180\n",
      "        64        9430.8979          +0.2168\n",
      "        65        9431.1137          +0.2158\n",
      "        66        9431.3285          +0.2148\n",
      "        67        9431.5426          +0.2140\n",
      "        68        9431.7559          +0.2134\n",
      "        69        9431.9687          +0.2128\n",
      "        70        9432.1812          +0.2124\n",
      "        71        9432.3934          +0.2122\n",
      "        72        9432.6054          +0.2121\n",
      "        73        9432.8175          +0.2121\n",
      "        74        9433.0298          +0.2123\n",
      "        75        9433.2425          +0.2126\n",
      "        76        9433.4556          +0.2131\n",
      "        77        9433.6694          +0.2138\n",
      "        78        9433.8839          +0.2145\n",
      "        79        9434.0994          +0.2154\n",
      "        80        9434.3158          +0.2165\n",
      "        81        9434.5334          +0.2176\n",
      "        82        9434.7521          +0.2187\n",
      "        83        9434.9720          +0.2199\n",
      "        84        9435.1930          +0.2210\n",
      "        85        9435.4152          +0.2221\n",
      "        86        9435.6382          +0.2230\n",
      "        87        9435.8619          +0.2237\n",
      "        88        9436.0858          +0.2240\n",
      "        89        9436.3097          +0.2238\n",
      "        90        9436.5328          +0.2231\n",
      "        91        9436.7544          +0.2216\n",
      "        92        9436.9736          +0.2192\n",
      "        93        9437.1895          +0.2159\n",
      "        94        9437.4008          +0.2113\n",
      "        95        9437.6064          +0.2055\n",
      "        96        9437.8048          +0.1985\n",
      "        97        9437.9950          +0.1901\n",
      "        98        9438.1756          +0.1806\n",
      "        99        9438.3456          +0.1701\n",
      "       100        9438.5044          +0.1588\n",
      "       101        9438.6515          +0.1471\n",
      "       102        9438.7868          +0.1353\n",
      "       103        9438.9107          +0.1239\n",
      "       104        9439.0237          +0.1130\n",
      "       105        9439.1268          +0.1031\n",
      "       106        9439.2211          +0.0942\n",
      "       107        9439.3076          +0.0866\n",
      "       108        9439.3877          +0.0801\n",
      "       109        9439.4626          +0.0749\n",
      "       110        9439.5336          +0.0709\n",
      "       111        9439.6017          +0.0681\n",
      "       112        9439.6682          +0.0665\n",
      "       113        9439.7346          +0.0664\n",
      "       114        9439.8023          +0.0678\n",
      "       115        9439.8736          +0.0713\n",
      "       116        9439.9513          +0.0777\n",
      "       117        9440.0398          +0.0885\n",
      "       118        9440.1465          +0.1067\n",
      "       119        9440.2845          +0.1380\n",
      "       120        9440.4811          +0.1966\n",
      "       121        9440.8026          +0.3216\n",
      "       122        9441.4492          +0.6466\n",
      "       123        9443.0866          +1.6374\n",
      "       124        9446.5198          +3.4331\n",
      "       125        9447.0670          +0.5473\n",
      "       126        9447.0865          +0.0195\n",
      "       127        9447.1013          +0.0148\n",
      "       128        9447.1155          +0.0141\n",
      "       129        9447.1290          +0.0135\n",
      "       130        9447.1419          +0.0129\n",
      "       131        9447.1542          +0.0124\n",
      "       132        9447.1661          +0.0118\n",
      "       133        9447.1774          +0.0113\n",
      "       134        9447.1882          +0.0108\n",
      "       135        9447.1986          +0.0104\n",
      "       136        9447.2085          +0.0099\n",
      "         1        4246.4209             +nan\n",
      "         2        6261.4313       +2015.0104\n",
      "         3        6973.3662        +711.9349\n",
      "         4        7284.1217        +310.7555\n",
      "         5        7744.0761        +459.9544\n",
      "         6        8413.5747        +669.4986\n",
      "         7        9113.7985        +700.2238\n",
      "         8        9225.7783        +111.9798\n",
      "         9        9233.5834          +7.8051\n",
      "        10        9236.4521          +2.8687\n",
      "        11        9238.0416          +1.5895\n",
      "        12        9239.0792          +1.0376\n",
      "        13        9239.8533          +0.7742\n",
      "        14        9240.5826          +0.7293\n",
      "        15        9241.5318          +0.9492\n",
      "        16        9243.0235          +1.4916\n",
      "        17        9245.5906          +2.5671\n",
      "        18        9250.9577          +5.3671\n",
      "        19        9265.6086         +14.6509\n",
      "        20        9314.0654         +48.4569\n",
      "        21        9460.3669        +146.3014\n",
      "        22        9561.8541        +101.4872\n",
      "        23        9573.4531         +11.5990\n",
      "        24        9574.5269          +1.0738\n",
      "        25        9575.0787          +0.5517\n",
      "        26        9575.5972          +0.5185\n",
      "        27        9576.0662          +0.4690\n",
      "        28        9576.4732          +0.4070\n",
      "        29        9576.8158          +0.3425\n",
      "        30        9577.0991          +0.2834\n",
      "        31        9577.3328          +0.2336\n",
      "        32        9577.5272          +0.1944\n",
      "        33        9577.6920          +0.1648\n",
      "        34        9577.8350          +0.1431\n",
      "        35        9577.9624          +0.1273\n",
      "        36        9578.0783          +0.1159\n",
      "        37        9578.1857          +0.1075\n",
      "        38        9578.2867          +0.1010\n",
      "        39        9578.3827          +0.0959\n",
      "        40        9578.4744          +0.0917\n",
      "        41        9578.5624          +0.0880\n",
      "        42        9578.6470          +0.0847\n",
      "        43        9578.7285          +0.0815\n",
      "        44        9578.8071          +0.0786\n",
      "        45        9578.8828          +0.0757\n",
      "        46        9578.9556          +0.0729\n",
      "        47        9579.0258          +0.0701\n",
      "        48        9579.0932          +0.0674\n",
      "        49        9579.1580          +0.0648\n",
      "        50        9579.2202          +0.0622\n",
      "        51        9579.2798          +0.0597\n",
      "        52        9579.3370          +0.0572\n",
      "        53        9579.3918          +0.0548\n",
      "        54        9579.4442          +0.0524\n",
      "        55        9579.4944          +0.0502\n",
      "        56        9579.5423          +0.0480\n",
      "        57        9579.5881          +0.0458\n",
      "        58        9579.6319          +0.0438\n",
      "        59        9579.6737          +0.0418\n",
      "        60        9579.7136          +0.0399\n",
      "        61        9579.7517          +0.0381\n",
      "        62        9579.7881          +0.0364\n",
      "        63        9579.8228          +0.0347\n",
      "        64        9579.8559          +0.0331\n",
      "        65        9579.8875          +0.0316\n",
      "        66        9579.9176          +0.0301\n",
      "        67        9579.9464          +0.0288\n",
      "        68        9579.9738          +0.0275\n",
      "        69        9580.0000          +0.0262\n",
      "        70        9580.0251          +0.0250\n",
      "        71        9580.0490          +0.0239\n",
      "        72        9580.0718          +0.0228\n",
      "        73        9580.0936          +0.0218\n",
      "        74        9580.1145          +0.0209\n",
      "        75        9580.1344          +0.0200\n",
      "        76        9580.1535          +0.0191\n",
      "        77        9580.1718          +0.0183\n",
      "        78        9580.1893          +0.0175\n",
      "        79        9580.2061          +0.0168\n",
      "        80        9580.2221          +0.0161\n",
      "        81        9580.2375          +0.0154\n",
      "        82        9580.2523          +0.0148\n",
      "        83        9580.2665          +0.0142\n",
      "        84        9580.2802          +0.0136\n",
      "        85        9580.2933          +0.0131\n",
      "        86        9580.3059          +0.0126\n",
      "        87        9580.3180          +0.0121\n",
      "        88        9580.3297          +0.0117\n",
      "        89        9580.3409          +0.0112\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        90        9580.3518          +0.0108\n",
      "        91        9580.3622          +0.0105\n",
      "        92        9580.3723          +0.0101\n",
      "        93        9580.3821          +0.0097\n",
      "         1        4178.6167             +nan\n",
      "         2        6169.2226       +1990.6060\n",
      "         3        6942.7479        +773.5252\n",
      "         4        7272.5144        +329.7665\n",
      "         5        7648.7179        +376.2035\n",
      "         6        8261.2001        +612.4823\n",
      "         7        8928.1654        +666.9652\n",
      "         8        9261.9422        +333.7768\n",
      "         9        9279.7375         +17.7953\n",
      "        10        9282.5630          +2.8256\n",
      "        11        9285.0140          +2.4510\n",
      "        12        9292.0904          +7.0764\n",
      "        13        9295.6746          +3.5842\n",
      "        14        9296.2481          +0.5735\n",
      "        15        9296.6487          +0.4005\n",
      "        16        9296.9867          +0.3380\n",
      "        17        9297.3106          +0.3239\n",
      "        18        9297.6442          +0.3336\n",
      "        19        9297.9944          +0.3501\n",
      "        20        9298.3554          +0.3610\n",
      "        21        9298.7142          +0.3588\n",
      "        22        9299.0558          +0.3416\n",
      "        23        9299.3671          +0.3114\n",
      "        24        9299.6400          +0.2729\n",
      "        25        9299.8717          +0.2317\n",
      "        26        9300.0645          +0.1928\n",
      "        27        9300.2238          +0.1593\n",
      "        28        9300.3557          +0.1319\n",
      "        29        9300.4658          +0.1101\n",
      "        30        9300.5590          +0.0932\n",
      "        31        9300.6391          +0.0802\n",
      "        32        9300.7095          +0.0704\n",
      "        33        9300.7727          +0.0632\n",
      "        34        9300.8305          +0.0578\n",
      "        35        9300.8843          +0.0538\n",
      "        36        9300.9351          +0.0508\n",
      "        37        9300.9835          +0.0484\n",
      "        38        9301.0300          +0.0465\n",
      "        39        9301.0750          +0.0450\n",
      "        40        9301.1186          +0.0436\n",
      "        41        9301.1610          +0.0424\n",
      "        42        9301.2023          +0.0413\n",
      "        43        9301.2426          +0.0403\n",
      "        44        9301.2820          +0.0393\n",
      "        45        9301.3204          +0.0384\n",
      "        46        9301.3578          +0.0375\n",
      "        47        9301.3944          +0.0366\n",
      "        48        9301.4302          +0.0357\n",
      "        49        9301.4651          +0.0349\n",
      "        50        9301.4991          +0.0341\n",
      "        51        9301.5324          +0.0332\n",
      "        52        9301.5648          +0.0324\n",
      "        53        9301.5965          +0.0317\n",
      "        54        9301.6274          +0.0309\n",
      "        55        9301.6575          +0.0301\n",
      "        56        9301.6868          +0.0294\n",
      "        57        9301.7154          +0.0286\n",
      "        58        9301.7433          +0.0279\n",
      "        59        9301.7705          +0.0272\n",
      "        60        9301.7970          +0.0265\n",
      "        61        9301.8228          +0.0258\n",
      "        62        9301.8479          +0.0251\n",
      "        63        9301.8724          +0.0245\n",
      "        64        9301.8962          +0.0238\n",
      "        65        9301.9194          +0.0232\n",
      "        66        9301.9420          +0.0226\n",
      "        67        9301.9639          +0.0220\n",
      "        68        9301.9853          +0.0214\n",
      "        69        9302.0061          +0.0208\n",
      "        70        9302.0263          +0.0202\n",
      "        71        9302.0459          +0.0196\n",
      "        72        9302.0650          +0.0191\n",
      "        73        9302.0835          +0.0186\n",
      "        74        9302.1016          +0.0180\n",
      "        75        9302.1191          +0.0175\n",
      "        76        9302.1361          +0.0170\n",
      "        77        9302.1527          +0.0165\n",
      "        78        9302.1687          +0.0161\n",
      "        79        9302.1843          +0.0156\n",
      "        80        9302.1994          +0.0151\n",
      "        81        9302.2141          +0.0147\n",
      "        82        9302.2284          +0.0143\n",
      "        83        9302.2423          +0.0138\n",
      "        84        9302.2557          +0.0134\n",
      "        85        9302.2687          +0.0130\n",
      "        86        9302.2814          +0.0126\n",
      "        87        9302.2937          +0.0123\n",
      "        88        9302.3056          +0.0119\n",
      "        89        9302.3171          +0.0115\n",
      "        90        9302.3283          +0.0112\n",
      "        91        9302.3392          +0.0109\n",
      "        92        9302.3497          +0.0105\n",
      "        93        9302.3599          +0.0102\n",
      "        94        9302.3698          +0.0099\n",
      "         1        4243.1018             +nan\n",
      "         2        6267.2160       +2024.1141\n",
      "         3        6990.7812        +723.5652\n",
      "         4        7301.2998        +310.5186\n",
      "         5        7764.2099        +462.9102\n",
      "         6        8483.2546        +719.0446\n",
      "         7        9244.6004        +761.3458\n",
      "         8        9345.6017        +101.0014\n",
      "         9        9347.8985          +2.2968\n",
      "        10        9349.2888          +1.3903\n",
      "        11        9350.2364          +0.9476\n",
      "        12        9350.8895          +0.6532\n",
      "        13        9351.3599          +0.4704\n",
      "        14        9351.7307          +0.3709\n",
      "        15        9352.0643          +0.3335\n",
      "        16        9352.4045          +0.3402\n",
      "        17        9352.7794          +0.3750\n",
      "        18        9353.2093          +0.4299\n",
      "        19        9353.7188          +0.5095\n",
      "        20        9354.3430          +0.6241\n",
      "        21        9355.1249          +0.7819\n",
      "        22        9356.1087          +0.9839\n",
      "        23        9357.3292          +1.2205\n",
      "        24        9358.7954          +1.4662\n",
      "        25        9360.4709          +1.6755\n",
      "        26        9362.2567          +1.7858\n",
      "        27        9363.9936          +1.7369\n",
      "        28        9365.5055          +1.5119\n",
      "        29        9366.6741          +1.1686\n",
      "        30        9367.4864          +0.8123\n",
      "        31        9368.0120          +0.5256\n",
      "        32        9368.3442          +0.3322\n",
      "        33        9368.5588          +0.2146\n",
      "        34        9368.7048          +0.1461\n",
      "        35        9368.8106          +0.1058\n",
      "        36        9368.8918          +0.0811\n",
      "        37        9368.9569          +0.0652\n",
      "        38        9369.0112          +0.0543\n",
      "        39        9369.0577          +0.0465\n",
      "        40        9369.0984          +0.0407\n",
      "        41        9369.1347          +0.0363\n",
      "        42        9369.1676          +0.0329\n",
      "        43        9369.1978          +0.0302\n",
      "        44        9369.2258          +0.0281\n",
      "        45        9369.2522          +0.0264\n",
      "        46        9369.2772          +0.0250\n",
      "        47        9369.3012          +0.0240\n",
      "        48        9369.3244          +0.0232\n",
      "        49        9369.3470          +0.0226\n",
      "        50        9369.3692          +0.0222\n",
      "        51        9369.3911          +0.0219\n",
      "        52        9369.4130          +0.0218\n",
      "        53        9369.4348          +0.0218\n",
      "        54        9369.4567          +0.0219\n",
      "        55        9369.4787          +0.0221\n",
      "        56        9369.5010          +0.0223\n",
      "        57        9369.5235          +0.0225\n",
      "        58        9369.5463          +0.0228\n",
      "        59        9369.5694          +0.0231\n",
      "        60        9369.5927          +0.0233\n",
      "        61        9369.6163          +0.0236\n",
      "        62        9369.6401          +0.0238\n",
      "        63        9369.6641          +0.0240\n",
      "        64        9369.6882          +0.0241\n",
      "        65        9369.7123          +0.0241\n",
      "        66        9369.7364          +0.0241\n",
      "        67        9369.7604          +0.0240\n",
      "        68        9369.7843          +0.0239\n",
      "        69        9369.8080          +0.0237\n",
      "        70        9369.8313          +0.0234\n",
      "        71        9369.8544          +0.0230\n",
      "        72        9369.8770          +0.0226\n",
      "        73        9369.8992          +0.0222\n",
      "        74        9369.9209          +0.0217\n",
      "        75        9369.9421          +0.0212\n",
      "        76        9369.9627          +0.0206\n",
      "        77        9369.9826          +0.0200\n",
      "        78        9370.0020          +0.0194\n",
      "        79        9370.0207          +0.0187\n",
      "        80        9370.0388          +0.0181\n",
      "        81        9370.0563          +0.0174\n",
      "        82        9370.0730          +0.0168\n",
      "        83        9370.0891          +0.0161\n",
      "        84        9370.1046          +0.0155\n",
      "        85        9370.1194          +0.0148\n",
      "        86        9370.1336          +0.0142\n",
      "        87        9370.1472          +0.0136\n",
      "        88        9370.1602          +0.0130\n",
      "        89        9370.1726          +0.0124\n",
      "        90        9370.1845          +0.0118\n",
      "        91        9370.1958          +0.0113\n",
      "        92        9370.2065          +0.0108\n",
      "        93        9370.2168          +0.0103\n",
      "        94        9370.2266          +0.0098\n",
      "         1        4247.3049             +nan\n",
      "         2        6270.6734       +2023.3685\n",
      "         3        6989.7674        +719.0940\n",
      "         4        7304.6852        +314.9177\n",
      "         5        7778.0885        +473.4034\n",
      "         6        8516.8844        +738.7959\n",
      "         7        9272.3957        +755.5113\n",
      "         8        9375.7457        +103.3500\n",
      "         9        9382.8194          +7.0736\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        10        9387.2071          +4.3877\n",
      "        11        9392.1151          +4.9081\n",
      "        12        9401.0144          +8.8993\n",
      "        13        9425.6580         +24.6436\n",
      "        14        9506.5476         +80.8896\n",
      "        15        9669.2276        +162.6800\n",
      "        16        9692.9927         +23.7651\n",
      "        17        9693.4886          +0.4960\n",
      "        18        9693.7894          +0.3007\n",
      "        19        9694.1035          +0.3141\n",
      "        20        9694.4853          +0.3818\n",
      "        21        9694.9522          +0.4669\n",
      "        22        9695.4984          +0.5462\n",
      "        23        9696.0969          +0.5985\n",
      "        24        9696.7056          +0.6088\n",
      "        25        9697.2801          +0.5744\n",
      "        26        9697.7865          +0.5064\n",
      "        27        9698.2096          +0.4231\n",
      "        28        9698.5512          +0.3417\n",
      "        29        9698.8243          +0.2731\n",
      "        30        9699.0454          +0.2211\n",
      "        31        9699.2293          +0.1839\n",
      "        32        9699.3867          +0.1574\n",
      "        33        9699.5235          +0.1368\n",
      "        34        9699.6421          +0.1187\n",
      "        35        9699.7444          +0.1022\n",
      "        36        9699.8326          +0.0883\n",
      "        37        9699.9102          +0.0775\n",
      "        38        9699.9799          +0.0698\n",
      "        39        9700.0443          +0.0644\n",
      "        40        9700.1049          +0.0606\n",
      "        41        9700.1626          +0.0577\n",
      "        42        9700.2182          +0.0555\n",
      "        43        9700.2719          +0.0537\n",
      "        44        9700.3240          +0.0522\n",
      "        45        9700.3748          +0.0508\n",
      "        46        9700.4243          +0.0495\n",
      "        47        9700.4726          +0.0483\n",
      "        48        9700.5198          +0.0472\n",
      "        49        9700.5659          +0.0461\n",
      "        50        9700.6109          +0.0450\n",
      "        51        9700.6549          +0.0440\n",
      "        52        9700.6979          +0.0430\n",
      "        53        9700.7399          +0.0420\n",
      "        54        9700.7810          +0.0411\n",
      "        55        9700.8212          +0.0401\n",
      "        56        9700.8604          +0.0392\n",
      "        57        9700.8987          +0.0383\n",
      "        58        9700.9361          +0.0374\n",
      "        59        9700.9727          +0.0366\n",
      "        60        9701.0085          +0.0357\n",
      "        61        9701.0434          +0.0349\n",
      "        62        9701.0775          +0.0341\n",
      "        63        9701.1109          +0.0333\n",
      "        64        9701.1434          +0.0326\n",
      "        65        9701.1753          +0.0318\n",
      "        66        9701.2063          +0.0311\n",
      "        67        9701.2367          +0.0304\n",
      "        68        9701.2663          +0.0296\n",
      "        69        9701.2953          +0.0290\n",
      "        70        9701.3236          +0.0283\n",
      "        71        9701.3512          +0.0276\n",
      "        72        9701.3781          +0.0270\n",
      "        73        9701.4044          +0.0263\n",
      "        74        9701.4301          +0.0257\n",
      "        75        9701.4552          +0.0251\n",
      "        76        9701.4797          +0.0245\n",
      "        77        9701.5035          +0.0239\n",
      "        78        9701.5268          +0.0233\n",
      "        79        9701.5495          +0.0227\n",
      "        80        9701.5717          +0.0222\n",
      "        81        9701.5933          +0.0216\n",
      "        82        9701.6143          +0.0211\n",
      "        83        9701.6348          +0.0205\n",
      "        84        9701.6548          +0.0200\n",
      "        85        9701.6743          +0.0195\n",
      "        86        9701.6932          +0.0190\n",
      "        87        9701.7117          +0.0184\n",
      "        88        9701.7296          +0.0179\n",
      "        89        9701.7471          +0.0175\n",
      "        90        9701.7641          +0.0170\n",
      "        91        9701.7806          +0.0165\n",
      "        92        9701.7966          +0.0160\n",
      "        93        9701.8122          +0.0156\n",
      "        94        9701.8273          +0.0151\n",
      "        95        9701.8420          +0.0147\n",
      "        96        9701.8562          +0.0142\n",
      "        97        9701.8700          +0.0138\n",
      "        98        9701.8834          +0.0134\n",
      "        99        9701.8964          +0.0130\n",
      "       100        9701.9090          +0.0126\n",
      "       101        9701.9211          +0.0122\n",
      "       102        9701.9329          +0.0118\n",
      "       103        9701.9443          +0.0114\n",
      "       104        9701.9553          +0.0110\n",
      "       105        9701.9659          +0.0106\n",
      "       106        9701.9762          +0.0103\n",
      "       107        9701.9861          +0.0099\n",
      "         1        4261.9230             +nan\n",
      "         2        6279.1861       +2017.2630\n",
      "         3        6993.3903        +714.2042\n",
      "         4        7302.5018        +309.1116\n",
      "         5        7782.6826        +480.1808\n",
      "         6        8502.6422        +719.9596\n",
      "         7        9230.1890        +727.5468\n",
      "         8        9340.0988        +109.9098\n",
      "         9        9347.1452          +7.0464\n",
      "        10        9350.3483          +3.2031\n",
      "        11        9351.7366          +1.3883\n",
      "        12        9352.6891          +0.9526\n",
      "        13        9354.8768          +2.1876\n",
      "        14        9362.8730          +7.9962\n",
      "        15        9364.7041          +1.8311\n",
      "        16        9365.8966          +1.1925\n",
      "        17        9367.2105          +1.3138\n",
      "        18        9368.5496          +1.3391\n",
      "        19        9369.7818          +1.2323\n",
      "        20        9370.8102          +1.0284\n",
      "        21        9371.5970          +0.7868\n",
      "        22        9372.1602          +0.5632\n",
      "        23        9372.5491          +0.3889\n",
      "        24        9372.8180          +0.2688\n",
      "        25        9373.0103          +0.1924\n",
      "        26        9373.1560          +0.1457\n",
      "        27        9373.2735          +0.1174\n",
      "        28        9373.3734          +0.0999\n",
      "        29        9373.4620          +0.0886\n",
      "        30        9373.5429          +0.0808\n",
      "        31        9373.6179          +0.0751\n",
      "        32        9373.6884          +0.0705\n",
      "        33        9373.7550          +0.0666\n",
      "        34        9373.8182          +0.0632\n",
      "        35        9373.8783          +0.0601\n",
      "        36        9373.9355          +0.0573\n",
      "        37        9373.9901          +0.0546\n",
      "        38        9374.0422          +0.0520\n",
      "        39        9374.0918          +0.0496\n",
      "        40        9374.1392          +0.0474\n",
      "        41        9374.1844          +0.0452\n",
      "        42        9374.2275          +0.0431\n",
      "        43        9374.2686          +0.0411\n",
      "        44        9374.3078          +0.0392\n",
      "        45        9374.3452          +0.0374\n",
      "        46        9374.3809          +0.0357\n",
      "        47        9374.4149          +0.0340\n",
      "        48        9374.4473          +0.0324\n",
      "        49        9374.4783          +0.0309\n",
      "        50        9374.5078          +0.0295\n",
      "        51        9374.5359          +0.0281\n",
      "        52        9374.5627          +0.0268\n",
      "        53        9374.5882          +0.0255\n",
      "        54        9374.6126          +0.0243\n",
      "        55        9374.6358          +0.0232\n",
      "        56        9374.6579          +0.0221\n",
      "        57        9374.6789          +0.0211\n",
      "        58        9374.6990          +0.0201\n",
      "        59        9374.7181          +0.0191\n",
      "        60        9374.7364          +0.0182\n",
      "        61        9374.7537          +0.0174\n",
      "        62        9374.7702          +0.0165\n",
      "        63        9374.7860          +0.0157\n",
      "        64        9374.8010          +0.0150\n",
      "        65        9374.8153          +0.0143\n",
      "        66        9374.8288          +0.0136\n",
      "        67        9374.8418          +0.0129\n",
      "        68        9374.8541          +0.0123\n",
      "        69        9374.8658          +0.0117\n",
      "        70        9374.8770          +0.0112\n",
      "        71        9374.8876          +0.0106\n",
      "        72        9374.8978          +0.0101\n",
      "        73        9374.9074          +0.0096\n"
     ]
    }
   ],
   "source": [
    "# list kosong untuk kumpulan model\n",
    "list_model = []\n",
    "\n",
    "for channel in data:\n",
    "    X = np.array(data[channel]).reshape(-1, 1)\n",
    "    m = GMMHMM(n_components=3, n_mix=2, \n",
    "               n_iter=1000, random_state=100,\n",
    "               verbose=True).fit(X)\n",
    "    logprob = m.score(X)\n",
    "    \n",
    "    list_model.append([m, logprob])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Channel 0 | logprob =  9699.217232859062\n",
      "Channel 1 | logprob =  9289.025420453056\n",
      "Channel 2 | logprob =  9447.217935395309\n",
      "Channel 3 | logprob =  9580.391475977309\n",
      "Channel 4 | logprob =  9302.379338420968\n",
      "Channel 5 | logprob =  9370.23591215467\n",
      "Channel 6 | logprob =  9701.9956548661\n",
      "Channel 7 | logprob =  9374.91654368354\n"
     ]
    }
   ],
   "source": [
    "# tampilkan logprob masing-masing channel\n",
    "for i in range(len(list_model)):\n",
    "    m, logprob = list_model[i]\n",
    "    print('Channel', i, '| logprob = ', logprob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "best_model, logprob = list_model[6][0], list_model[6][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9701.9956548661"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logprob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 1., 0.])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.startprob_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[9.99318739e-001, 2.11695422e-248, 6.81260612e-004],\n",
       "       [5.20642827e-003, 9.94793572e-001, 0.00000000e+000],\n",
       "       [1.62484337e-092, 2.01999787e-003, 9.97980002e-001]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.transmat_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.71034481, 0.28965519],\n",
       "       [0.7917666 , 0.2082334 ],\n",
       "       [0.34823937, 0.65176063]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.weights_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[0.14744399],\n",
       "        [0.14942804]],\n",
       "\n",
       "       [[0.12399797],\n",
       "        [0.20232037]],\n",
       "\n",
       "       [[0.16237843],\n",
       "        [0.16073996]]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.means_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[2.59951062e-06],\n",
       "        [8.18613864e-06]],\n",
       "\n",
       "       [[4.76390100e-06],\n",
       "        [1.56423560e-03]],\n",
       "\n",
       "       [[3.38012923e-06],\n",
       "        [1.72535029e-05]]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.covars_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ConvergenceMonitor(history=[9701.976168105328, 9701.986084463799], iter=107,\n",
       "          n_iter=1000, tol=0.01, verbose=True)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "best_model.monitor_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Draw Plot Duration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# waktu\n",
    "minutes = []\n",
    "time = 0\n",
    "for i in range(2156):\n",
    "    minutes.append(time)\n",
    "    if i < 43:\n",
    "        time += 5\n",
    "    else:\n",
    "        time += 10\n",
    "type(minutes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.index = minutes\n",
    "data.index.name = 'time'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>21295</th>\n",
       "      <td>0.211522</td>\n",
       "      <td>0.208390</td>\n",
       "      <td>0.210022</td>\n",
       "      <td>0.210039</td>\n",
       "      <td>0.211658</td>\n",
       "      <td>0.205170</td>\n",
       "      <td>0.211905</td>\n",
       "      <td>0.208512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21305</th>\n",
       "      <td>0.261481</td>\n",
       "      <td>0.325306</td>\n",
       "      <td>0.281206</td>\n",
       "      <td>0.274782</td>\n",
       "      <td>0.322789</td>\n",
       "      <td>0.282524</td>\n",
       "      <td>0.267773</td>\n",
       "      <td>0.300020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21315</th>\n",
       "      <td>0.290100</td>\n",
       "      <td>0.282309</td>\n",
       "      <td>0.377078</td>\n",
       "      <td>0.288593</td>\n",
       "      <td>0.290287</td>\n",
       "      <td>0.347876</td>\n",
       "      <td>0.301884</td>\n",
       "      <td>0.265579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21325</th>\n",
       "      <td>0.279284</td>\n",
       "      <td>0.302474</td>\n",
       "      <td>0.262419</td>\n",
       "      <td>0.287338</td>\n",
       "      <td>0.291355</td>\n",
       "      <td>0.274452</td>\n",
       "      <td>0.264980</td>\n",
       "      <td>0.320975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21335</th>\n",
       "      <td>0.326161</td>\n",
       "      <td>0.289407</td>\n",
       "      <td>0.323861</td>\n",
       "      <td>0.349152</td>\n",
       "      <td>0.302272</td>\n",
       "      <td>0.324690</td>\n",
       "      <td>0.358188</td>\n",
       "      <td>0.306245</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              0         1         2         3         4         5         6  \\\n",
       "time                                                                          \n",
       "21295  0.211522  0.208390  0.210022  0.210039  0.211658  0.205170  0.211905   \n",
       "21305  0.261481  0.325306  0.281206  0.274782  0.322789  0.282524  0.267773   \n",
       "21315  0.290100  0.282309  0.377078  0.288593  0.290287  0.347876  0.301884   \n",
       "21325  0.279284  0.302474  0.262419  0.287338  0.291355  0.274452  0.264980   \n",
       "21335  0.326161  0.289407  0.323861  0.349152  0.302272  0.324690  0.358188   \n",
       "\n",
       "              7  \n",
       "time             \n",
       "21295  0.208512  \n",
       "21305  0.300020  \n",
       "21315  0.265579  \n",
       "21325  0.320975  \n",
       "21335  0.306245  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFr9JREFUeJzt3X+QXWd93/H3p8I2AzhBRoK4shfJrcrgNGCcHUNiCCYNQnZbRKZ0Kk8aBLVHMwxuSX/NmDKDGdM/QpiSGQYHoxQNP5rYJPxo1BkRo8YQtyF2vCbGP2O8CKhVuZFAjsGB2JH59o97NHNZ7717tXt3z91z36+ZO3vuc37c5zx7z/ee8zzPOU+qCknS9Pg7bWdAkrS2DPySNGUM/JI0ZQz8kjRlDPySNGUM/JI0ZQz8kjRlDPySNGUM/JI0ZZ7VdgYWs2nTptq6dWvb2ZCkdeOuu+76TlVtHmXZiQz8W7duZW5uru1sSNK6keTboy5rVY8kTRkDvyRNGQO/JE0ZA78kTRkDvyRNmSUDf5Lzk3wpyYNJ7k/yzkWWSZIPJZlPck+Si/vm7UnycPPaM+4dkCSdnlG6c54E/n1VfTXJ2cBdSQ5V1QN9y1wObG9erwQ+ArwyyTnAdcAsUM26B6rqsbHuhSRpZEsG/qp6FHi0m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TM9DlV1G70xIfqNpTyaeT9RVX9avSP5k33bmngDymaQXcDNVfVkVX0TmKd3nC16rDVnr78IfKZZv7+cJ15VPVpVX22mvw88SG988E5+d7oS+BcbEH5axk0s4ItJ7mrGLQZ4UVU9Cr0vNPDCJn1QOXW9/MZVHlua6YXp6901TXXF/lNVGZx+2bwA+KuqOrkgfd1JshV4BXAHHf3udCXwjzyoewddWlUXA5cD70jyC0OWHVRO01p+p1seXSynjwB/D7gIeBT4L036VJZNkucBnwV+raq+N2zRRdLWTfl0JfCPPKh711TV0ebvMeDz9C7F/7K5tKT5e6xZfFA5db38xlUeR5rphenrVlX9ZVU9XVU/An6b3vcHTr9svkOvuuNZC9LXjSRn0Av6v1NVn2uSO/nd6UrgH2VA+M5J8twkZ5+aBnYA99Hb91O9CfYAf9BMHwDe0vRIeBXweHP5eguwI8nG5lJ/R5PWFWMpj2be95O8qqnTfkvfttalU0Gt8cv0vj/QK5vdSc5Ksg3YTq9xctFjram3/hLw5mb9/nKeeM3/82PAg1X1wb5Z3fzutN2aPq4XvVb2r9PrcfDutvOzRvt8Ab1eFV8D7j+13/TqW/8IeLj5e06THuCGpozuBWb7tvWv6DXgzQNva3vfVlAmN9GrsvhbemdZV42zPIBZesHxG8CHaW6CXA+vAWXzqWbf76EXzM7tW/7dzX4+RF8PlEHHWvN9/LOmzH4fOKvtfT6Nsnk1vaqXe4C7m9cVXf3ueOeuJE2ZrlT1SJJGZOCXpClj4JekKWPgl6QpY+CXpClj4JekKWPgl6QpY+CXpCnz/wGC6ep1+dcKMgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# mendefinisikan data x y graph\n",
    "x = data.index\n",
    "y = best_model.predict(data[6].values.reshape(-1, 1))\n",
    "plt.plot(x, y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['state channel 6'] = best_model.predict(data[6].values.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>state channel 6</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.124086</td>\n",
       "      <td>0.123077</td>\n",
       "      <td>0.124692</td>\n",
       "      <td>0.123098</td>\n",
       "      <td>0.121993</td>\n",
       "      <td>0.120885</td>\n",
       "      <td>0.120650</td>\n",
       "      <td>0.122520</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.125157</td>\n",
       "      <td>0.121047</td>\n",
       "      <td>0.119458</td>\n",
       "      <td>0.121360</td>\n",
       "      <td>0.123017</td>\n",
       "      <td>0.120512</td>\n",
       "      <td>0.123048</td>\n",
       "      <td>0.122855</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.125133</td>\n",
       "      <td>0.125864</td>\n",
       "      <td>0.122109</td>\n",
       "      <td>0.126549</td>\n",
       "      <td>0.124533</td>\n",
       "      <td>0.121847</td>\n",
       "      <td>0.120396</td>\n",
       "      <td>0.123333</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.125903</td>\n",
       "      <td>0.122256</td>\n",
       "      <td>0.125582</td>\n",
       "      <td>0.123162</td>\n",
       "      <td>0.122565</td>\n",
       "      <td>0.122018</td>\n",
       "      <td>0.124485</td>\n",
       "      <td>0.125027</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.123719</td>\n",
       "      <td>0.128365</td>\n",
       "      <td>0.121615</td>\n",
       "      <td>0.123504</td>\n",
       "      <td>0.119830</td>\n",
       "      <td>0.126062</td>\n",
       "      <td>0.123403</td>\n",
       "      <td>0.122291</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             0         1         2         3         4         5         6  \\\n",
       "time                                                                         \n",
       "0     0.124086  0.123077  0.124692  0.123098  0.121993  0.120885  0.120650   \n",
       "5     0.125157  0.121047  0.119458  0.121360  0.123017  0.120512  0.123048   \n",
       "10    0.125133  0.125864  0.122109  0.126549  0.124533  0.121847  0.120396   \n",
       "15    0.125903  0.122256  0.125582  0.123162  0.122565  0.122018  0.124485   \n",
       "20    0.123719  0.128365  0.121615  0.123504  0.119830  0.126062  0.123403   \n",
       "\n",
       "             7  state channel 6  \n",
       "time                             \n",
       "0     0.122520                1  \n",
       "5     0.122855                1  \n",
       "10    0.123333                1  \n",
       "15    0.125027                1  \n",
       "20    0.122291                1  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([ 1345,  1355,  1365,  1375,  1385,  1395,  1405,  1415,  1425,\n",
       "             1435,\n",
       "            ...\n",
       "            15895, 15905, 15915, 15925, 15935, 15945, 15955, 15965, 15975,\n",
       "            15985],\n",
       "           dtype='int64', name='time', length=1465)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state_0 = data[data['state channel 6'] == 0].index\n",
    "state_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14640\n"
     ]
    }
   ],
   "source": [
    "duration_state0 = state_0[-1] - state_0[0]\n",
    "print(duration_state0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([15995, 16005, 16015, 16025, 16035, 16045, 16055, 16065, 16075,\n",
       "            16085,\n",
       "            ...\n",
       "            20875, 20885, 20895, 20905, 20915, 20925, 20935, 20945, 20955,\n",
       "            20965],\n",
       "           dtype='int64', name='time', length=498)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state_2 = data[data['state channel 6'] == 2].index\n",
    "state_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4970\n"
     ]
    }
   ],
   "source": [
    "duration_state2 = state_2[-1] - state_2[0]\n",
    "print(duration_state2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([    0,     5,    10,    15,    20,    25,    30,    35,    40,\n",
       "               45,\n",
       "            ...\n",
       "            21245, 21255, 21265, 21275, 21285, 21295, 21305, 21315, 21325,\n",
       "            21335],\n",
       "           dtype='int64', name='time', length=193)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state_1 = data[data['state channel 6'] == 1].index\n",
    "state_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1695\n"
     ]
    }
   ],
   "source": [
    "duration_state1 = (1335 - 0) + (21335 - 20975)\n",
    "print(duration_state1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[14640.0, 847.5, 4970.0]\n"
     ]
    }
   ],
   "source": [
    "mean_duration = [duration_state0/1, duration_state1/2, duration_state2/1]\n",
    "print(mean_duration)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 487, 0]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "std_duration = [0, int(487.5), 0]\n",
    "std_duration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "duration_state1_list = [1335, 360]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "487.5"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "std_duration_state1 = np.std(duration_state1_list)\n",
    "std_duration_state1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "# RUL\n",
    "conf = 0.95 # confidence coefficient\n",
    "\n",
    "# RUL Upper\n",
    "rul_upper = (mean_duration[0] + conf * std_duration[0]) + \\\n",
    "            (mean_duration[1] + conf * std_duration[1]) + \\\n",
    "            (mean_duration[2] + conf * std_duration[2])\n",
    "\n",
    "# RUL Mean\n",
    "rul_mean = (mean_duration[0]) + \\\n",
    "           (mean_duration[1]) + \\\n",
    "           (mean_duration[2])\n",
    "\n",
    "# RUL lower\n",
    "rul_lower = (mean_duration[0] - conf * std_duration[0]) + \\\n",
    "            (mean_duration[1] - conf * std_duration[1]) + \\\n",
    "            (mean_duration[2] - conf * std_duration[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RUL Upper:  20920.15\n",
      "RUL Mean:  20457.5\n",
      "RUL Lower:  19994.85\n"
     ]
    }
   ],
   "source": [
    "print('RUL Upper: ', rul_upper)\n",
    "print('RUL Mean: ', rul_mean)\n",
    "print('RUL Lower: ', rul_lower)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
